# -*- coding:utf-8 -*-

import imageio
import os
import cv2

cur_path = os.getcwd()
os.chdir( cur_path )

simu_num = 20
simu_iter = 200
iter_gap = 5
dt = 0.5 #ms

folder = cur_path + '\\'
append1 = 'pics0719_1431'
folder_save = cur_path + '\\gif\\' + append1 +'\\'
if(False == os.path.exists(folder_save)):
    os.mkdir(folder_save)
        
for j in range(0,simu_num,1):
    append2 = str(j).zfill(5) #+ '\\'

    img_names = [(str(i).zfill(5)+'.bmp') for i in range(0,simu_iter,iter_gap)]
    gif_images = []
    
    t0 = 0
    t_iter = 0
    
    for name in img_names:
        t_iter = t_iter + iter_gap
        img = imageio.imread(folder + append1 + '\\' + append2 + '\\' + name)
        time_label = 'time:' + str( (t0 + t_iter * dt) ) + 'ms'
        b = cv2.putText(img,time_label, (600,160), cv2.FONT_HERSHEY_SIMPLEX, 0.7,(255,255,255), 1, cv2.LINE_AA)
        # cv2.imshow("add_text",img)
        # cv2.waitKey()
        gif_images.append(img)
        
    imageio.mimsave((folder_save + append2 + '.gif'),gif_images,fps=10)





